package com.cn.reportforms.controller;

import com.cn.reportforms.entity.ExportSetting;
import com.cn.reportforms.entity.ExportSettingQuery;
import com.cn.reportforms.entity.ExportSettingWithBLOBs;
import com.cn.reportforms.service.ExportSettingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：
 *
 * @author chen_q_i@163.com
 * 2019/4/19 : 10:34.
 * @version : 1.0
 */
@RestController
@RequestMapping("/export/admin/setting")
public class ExportSettingController {
    private static final Logger logger = LoggerFactory.getLogger(ExportSettingController.class);

    @Autowired
    private ExportSettingService exportSettingService;


    @GetMapping("/list")
    public Object getList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                         @RequestParam(required = false, defaultValue = "25") Integer pageSize) {
        ExportSettingQuery query = new ExportSettingQuery();

        PageHelper.startPage(pageNum,pageSize);
        List<ExportSetting> exportSettings = exportSettingService.selectByExample(query);
        PageInfo pageInfo=new PageInfo(exportSettings);
        return pageInfo;
    }


    @GetMapping("/checkName")
    public Object checkName(@RequestParam(required = false, defaultValue = "") String excelName) {
        ExportSettingQuery query = new ExportSettingQuery();
        query.createCriteria().andExcelNameEqualTo(excelName);
        int i = exportSettingService.countByExample(query);
        return i;
    }

    @PostMapping("/add")
    public Object addSetting(ExportSettingWithBLOBs exportSettingWithBLOBs) {
        exportSettingService.insert(exportSettingWithBLOBs);
        return null;
    }

    @GetMapping("/id")
    public Object getById(Long id) {
        ExportSettingWithBLOBs exportSettingWithBLOBs = exportSettingService.selectByPrimaryKey(id);
        return exportSettingWithBLOBs;
    }

    @PostMapping("/update")
    public Object aupdateSetting(ExportSettingWithBLOBs exportSettingWithBLOBs) {
        exportSettingService.updateByPrimaryKeySelective(exportSettingWithBLOBs);
        return null;
    }

}
